<?php


namespace app\api\controller;


use app\service\model\OrderModel;
use app\service\Y;

class Pay extends AuthApi
{

    /**
     * 获取订单支付信息
     * @return \think\response\Json
     * @throws \EasyWeChat\Kernel\Exceptions\InvalidArgumentException
     * @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException
     * @throws \GuzzleHttp\Exception\GuzzleException
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\DbException
     * @throws \think\db\exception\ModelNotFoundException
     */
    public function order_pay_info(): \think\response\Json
    {
        $id = input('param.id', 0);
        $order = OrderModel::where('id', '=', $id)
            ->where('member_id', '=', $this->member->id)->find();

        if (!$order) {
            return Y::error('订单不存在');
        }

        if ($order->status != 1) {
            return Y::error('订单不是待支付状态');
        }

        $pay_info = \app\service\business\Pay::wechat_pay([
            'body' => 'YY蛋糕 - 订单支付',
            'order_no' => $order->order_no,
//            'total' => $order->unpaid * 100,
            'total' => 1,
            'notify_url' => request()->domain() . '/pay/wxpay_notify/order',
            'openid' => $order->member->xcx_openid
        ]);

        return Y::success($pay_info, '订单支付信息');
    }
}